Skip to content

Forward streaming authentication challenges to URLProtocolClient#14

Open
kikeenrique wants to merge 5 commits into
mattt:mainfrom
kikeenrique:fix/playback-urlprotocol-auth-challenges
Open

Forward streaming authentication challenges to URLProtocolClient#14
kikeenrique wants to merge 5 commits into
mattt:mainfrom
kikeenrique:fix/playback-urlprotocol-auth-challenges

Conversation

@kikeenrique
Copy link
Copy Markdown

This PR was AI assisted.
This fixes authentication challenge handling for Replay’s live/passthrough streaming path.

When PlaybackURLProtocol falls through to the network, it creates an internal URLSession with StreamingDelegate so responses can be streamed incrementally. That delegate previously did not forward URLSessionTask authentication challenges back to the original URLProtocolClient, so callers had no chance to handle credentials, cancellation, trust decisions, or custom auth behavior during streamed requests.

The PR fixes this by:

  • Giving StreamingDelegate a weak reference to the active PlaybackURLProtocol
  • Implementing urlSession(_:task:didReceive:completionHandler:)
  • Rebuilding the challenge with a URLAuthenticationChallengeSender bridge
  • Translating client decisions back into the URLSession completion handler
  • Adding a regression test for challenge forwarding
  • Marking PlaybackTests with .playbackIsolated because the suite touches global URLProtocol / PlaybackStore state

fix: Bridge URLSession authentication challenge callbacks through PlaybackURLProtocol
     so clients can handle trust and credential decisions during streamed live playback requests.
fix: Make the URLProtocolClient test helper explicitly Sendable and use a
  cross-platform authentication method for synthetic challenges.
test: fix. PlaybackTests touches process-wide URLProtocol registration and shared
  PlaybackStore state directly. Use playback isolation in addition to serialized
  execution so these tests cannot race with other suites using .replay(...).
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes authentication challenge handling for Replay’s live/passthrough streaming path by forwarding URLSessionTask authentication challenges from the internal streaming URLSession back to the originating URLProtocolClient, enabling callers to provide credentials, cancel, or apply custom trust handling during streamed requests.

Changes:

  • Add a back-reference from the streaming URLSession delegate to the active PlaybackURLProtocol and forward task-level authentication challenges to the URLProtocolClient.
  • Introduce a URLAuthenticationChallengeSender bridge to translate URLProtocolClient challenge decisions into the URLSession completion-handler contract.
  • Add a regression test ensuring authentication challenges are forwarded, and mark PlaybackTests as .playbackIsolated to avoid cross-suite global state interference.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Sources/Replay/Playback.swift Forwards streamed-network-path auth challenges from URLSession to URLProtocolClient via a sender bridge.
Tests/ReplayTests/PlaybackTests.swift Adds a regression test for challenge forwarding and isolates the suite to prevent global URLProtocol/PlaybackStore interference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants